#include <bits/stdc++.h>
#include <vector>
using namespace std;

class Solution {
private:
    void dfsUnique(int k, vector<int>& nums, bool vis[], vector<int>& sub_ans,
                    vector<vector<int>>& ans)
    {
        int size = nums.size();
        if(k == size){
            ans.push_back(sub_ans);
            return;
        }
        for(int i=0; i<size; ++i){
            if(vis[i]) continue;
            vis[i] = true;
            sub_ans.push_back(nums[i]);
            dfsUnique(k+1, nums, vis, sub_ans, ans);
            sub_ans.pop_back();
            vis[i] = false;
            while(i+1<size && nums[i]==nums[i+1]) ++i;
        }
    }
public:
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> ans;
        bool *vis = new bool[nums.size()]{false};
        vector<int> sub_ans;
        dfsUnique(0, nums, vis, sub_ans, ans);
        delete[] vis;
        return ans;
    }
};

int main(){

}